package com.yzt.dynamicmodule.activity

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.yzt.dynamicmodule.R
import com.yzt.dynamicmodule.databinding.ActivityVideoScrollerPageBinding

import com.yzt.zhuju.activity.BaseViewBindingActivity
import com.yzt.zhuju.arouter.RouterDynamic
import com.yzt.zhuju.utils.BarUtils

/**
 * 作者：bobwang
 * 创建时间：2023-12-28 20:03:28
 * 描述：动态视频播放
 */
@Route(path = RouterDynamic.PATH_DYNAMIC_VIDEO_SCROLLER)
class DynamicVideoScrollerPageActivity :
    BaseViewBindingActivity<ActivityVideoScrollerPageBinding>() {

    override fun hideTitleBar() = true

    @Autowired
    @JvmField
    var dynamicId: String = ""

    @Autowired
    @JvmField
    var userId: String = ""

    override fun generateViewBinding(): ActivityVideoScrollerPageBinding {
        return ActivityVideoScrollerPageBinding.inflate(layoutInflater)
    }

    private var mCurrentFragment: Fragment? = null
    private var mDynamicVideoFragment: com.yzt.dynamicmodule.fragment.IndexDiscoverFragment? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarAlpha(this, 0)
        viewBinding.imgBack.setOnClickListener {
            finish()
        }

        mDynamicVideoFragment = com.yzt.dynamicmodule.fragment.IndexDiscoverFragment.getInstance(-1,userId,dynamicId)
        showFragment()
    }

    private fun showFragment() {
        if (mCurrentFragment != mDynamicVideoFragment) {
            val transaction = supportFragmentManager.beginTransaction()
            if (!supportFragmentManager.isDestroyed) {
                if (!mDynamicVideoFragment!!.isAdded) {
                    transaction.add(R.id.dynamic_fragment_scroller, mDynamicVideoFragment!!)
                        .commitAllowingStateLoss()
                } else {
                    transaction.show(mDynamicVideoFragment!!).commitAllowingStateLoss()
                }
                mCurrentFragment = mDynamicVideoFragment
            }
        }
    }
}
